//
//  LGDiscoverCell.m
//  lgdw
//
//  Created by Apple on 15/12/9.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "LGDiscoverCell.h"
#import "LGDiscover.h"
#import "LGBottonView.h"

#define Margen 10
@interface LGDiscoverCell ()
///  大图
@property (nonatomic, strong) UIImageView *iconView;
///  标题
@property (nonatomic, strong) UILabel *titleLabel;
///  分割线
@property (nonatomic, strong) UIView *lineView;

/// 下部视图
@property (nonatomic, strong) LGBottonView *bottomView;

/// 分割线
@property (nonatomic, strong) UIView *bottomLine;

/// 间隔
@property (nonatomic, strong) UIView *margnView;



@end

@implementation LGDiscoverCell

#pragma mark - /************** 显示信息 **************/
- (void)setDiscover:(LGDiscover *)discover {
    // 防止重用
    self.iconView.image = nil;
    self.titleLabel.text = nil;
    _discover = discover;
    self.bottomView.discover = discover;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:discover.image] placeholderImage:[UIImage imageNamed:@"placeholder_image"]];
        
    // 设置图片裁剪
    self.titleLabel.text = discover.title;
}

#pragma mark - /************** 重写 init 方法 **************/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    
    return self;
}
#pragma mark - /************** 设置界面 **************/
- (void)setupUI {
    
    self.backgroundColor = [[UIColor alloc] initWithWhite:1.0 alpha:1.0];;
    // 1.添加空间
    [self addSubview:self.iconView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.lineView];
    [self addSubview:self.bottomView];
    [self addSubview:self.bottomLine];
    [self addSubview:self.margnView];
    
    // 2.布局
    // 大图
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.top.mas_equalTo(self.mas_top);
        CGFloat heig = self.frame.size.width * 0.4;
        make.height.mas_equalTo(heig);
        
    }];
    // 标题
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconView.mas_bottom).offset(Margen);
        make.left.mas_equalTo(self.mas_left).offset(Margen);
        make.right.mas_equalTo(self.mas_right).offset(-Margen);
        
    }];
    // 线
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(Margen);
        make.height.mas_equalTo(1);
    }];
    // 下部视图
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-15);
    }];
    
    // 底线
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bottomView.mas_bottom);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.height.mas_equalTo(1);
    }];
    // 间隔
    [self.margnView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.bottomLine.mas_bottom);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.height.mas_equalTo(10);
    }];
}


#pragma mark - /************** 懒加载控件 **************/
// 大图
- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] initAndClipsToBounds];
    }
    return _iconView;
}
// 标题
- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] initWithTitle:nil FontSize:14 TextColor:nil];
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;
}

// 分割线
- (UIView *)lineView {
    if (_lineView == nil) {
        _lineView = [[UILabel alloc] init];
        _lineView.backgroundColor = [[UIColor alloc] initWithWhite:0.9 alpha:0.7];;
        
    }
    return _lineView;
}

// 下部视图
- (LGBottonView *)bottomView {
    if (_bottomView == nil) {
        _bottomView = [[LGBottonView alloc] init];
        
    }
    return _bottomView;
}

// 线
- (UIView *)bottomLine {
    if (_bottomLine == nil) {
        _bottomLine = [[UIView alloc] init];
        _bottomLine.backgroundColor = [[UIColor alloc] initWithRed:63 / 255.0 green:156 / 255.0 blue:157 / 255.0 alpha:1.0];;
        
    }
    return _bottomLine;
}

// 间隔
- (UIView *)margnView {
    
    if (_margnView == nil) {
        _margnView = [[UIView alloc] init];
        _margnView.backgroundColor = [[UIColor alloc] initWithWhite:0.95 alpha:1.0];
    }
    return _margnView;
}

@end
